<template>
    <view class="container">

        <!-- 投诉部分 -->
        <view class="section">
            <view class="section-title">
                <text class="complain-target">投诉对象</text>
                <text class="complain-info">{{ currentTripDetails.order.line.real_name }}({{
                    currentTripDetails.order.line.phone }})</text>
            </view>
            <view class="complaint-input">
                <textarea placeholder="投诉详细原因，仅平台方可查看" maxlength="100" v-model="complaintDetail"
                    @input="countComplaintChars"></textarea>
                <text class="char-count">{{ complaintCharCount }}/100</text>
            </view>
        </view>

        <!-- 提交按钮 -->
        <view class="submit-btn" @click="submit">提 交</view>

    </view>
</template>

<script>
export default {
    data() {
        return {
            complaintDetail: "",
            complaintCharCount: 0,
            currentTripId: null,
            currentTripDetails: {}
        };
    },
    onLoad(options) {
        this.currentTripId = options.id
        this.getPassengerTripDetails()
    },
    computed: {
        // 表单验证
        isCanSubmit() {
            if (this.complaintDetail) {
                return true
            }
            return false
        }
    },
    methods: {
        countComplaintChars(e) {
            this.complaintCharCount = e.detail.value.length;
        },
        async getPassengerTripDetails() {
            try {
                const res = await this.$http.get(`/h5/user/trip/passengerDetail/${this.currentTripId}`)
                this.currentTripDetails = res.data

            } catch (error) {}
        },
        // 提交乘客投诉
        async submit() {
            if (!this.isCanSubmit) {
                uni.showToast({
                    title: "请输入投诉详细原因",
                    icon: "none",
                });
                return;
            }
            let params = {
                content: this.complaintDetail
            }
            try {
                const res = await this.$http.post(`/h5/user/trip/complaint/${this.currentTripId}`, params);
                uni.showToast({
                    title: "提交成功",
                    icon: "success",
                });
                setTimeout(() => {
                    uni.navigateBack();
                }, 1000);
            } catch (error) {
                uni.showToast({ title: error.msg || '提交失败', icon: 'none' })
            }
        },
    },
};
</script>

<style scoped>
.container {
    padding: 20rpx 26rpx;
    height: 100%;
}

.section {
    background-color: #fff;
    padding: 26rpx 40rpx;
    margin-bottom: 20rpx;
    border-radius: 16rpx;
    height: 100%;
}

.section-title {
    margin-bottom: 26rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.section-title .complain-target {
    font-size: 32rpx;
    font-weight: 500;
    color: #0B1F20;
}

.section-title .complain-info {
    font-family: Source Han Sans CN, Source Han Sans CN;
    font-size: 28rpx;
    color: #999999;
}

.complaint-input {
    position: relative;
}

textarea {
    width: 100%;
    height: 320rpx;
    padding: 28rpx 24rpx;
    font-family: Source Han Sans CN, Source Han Sans CN;
    font-size: 28rpx;
    color: #999999;
    background: #F5F5F6;
    border-radius: 16rpx;
    box-sizing: border-box;
}

.char-count {
    position: absolute;
    right: 24rpx;
    bottom: 28rpx;
    font-size: 28rpx;
    color: #999;
}


.submit-btn {
    background: linear-gradient(90deg, #ff3f39 0%, #ff7937 100%);
    color: #fff;
    text-align: center;
    padding: 24rpx 0;
    border-radius: 16rpx;
    font-family: Source Han Sans CN, Source Han Sans CN;
    font-weight: 500;
    font-size: 36rpx;
    color: #FFFFFF;
    margin-bottom: 20rpx;
}
</style>
